export default {
	data() {
		return {
			headData: {
				name: '未登录',
				label: '未登录',
				img: '/static/duser.jpg'
			}
		}
	},
	_context: null,
	_bid: null,
	onLoad() {
		//初始化信息
		this._context = uni.core.getContext();
		this._bid = uni.core.bsessionid;
		this._loadHead(this._context, this._bid);
	},
	onShow() {
		//检测是否要更新头像
		var _this = this;
		uni.getStorage({
			key: 'updateHead',
			success(res) {
				if (res['data']) {
					_this._loadHead(_this._context, _this._bid);
					uni.removeStorage({
						key: 'updateHead'
					});
				}
			}
		});
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this._loadHead(this._context, this._bid);
			uni.stopPullDownRefresh();
			uni.core.message('刷新成功');
		}, 1000);
	},
	methods: {
		//加载用户信息
		_loadHead(_context, _bid) {
			var time = new Date().getTime();
			var _hurl = '';
			if (uni.p9version == 'clound') {
				_hurl = uni.core.rootPath + uni.api.get('currentPhoto');
			} else {
				_hurl = uni.core.rootPath + uni.api.get('downloadUserPhoto');
			}
			_hurl += '?bsessionid=' + _bid + '&t=' + time;
			this.headData = {
				name: _context['currentPersonName'],
				label: _context['currentOrgFullName'],
				img: _hurl
			};
		},
		_noapp() {
			uni.showToast({
				icon: 'none',
				title: '近期上线，敬请期待哦～',
				duration: 2000
			});
		},
		//退出登录
		_logout() {
			uni.core.confirm("温馨提示", '是否退出当前账号?', () => {
				uni.core.logout(() => {
					uni.reLaunch({
						url: '/pages/system/login/login'
					})
				})
			})
		},
		_toView: uni.core.openPage
	}
}
